/*
 * Copyright (C) 2015 Daniel Uppenkamp
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.maurersmarbles;

import com.google.common.base.Preconditions;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

/**
 *
 * @author Daniel Uppenkamp
 */
public class Play {

    /**
     * The card for this play.
     */
    protected Card card;
    /**
     * The set of moves for this play.
     */
    protected Set<Move> moves = new LinkedHashSet();

    /**
     * Creates a new Play.
     *
     * @param card the card for this play
     */
    public Play(Card card) {
        Preconditions.checkNotNull(card, "Null card");
        this.card = card;
    }

    /**
     * Adds the given move to the moves for this play.
     *
     * @param move the move to add
     */
    public void addMove(Move move) {
        Preconditions.checkNotNull(move, "Null move");
        moves.add(move);
    }

    /**
     * Adds the given moves to the moves for this play.
     *
     * @param moves the moves to add
     */
    public void addMoves(Set<Move> moves) {
        Preconditions.checkNotNull(moves, "Null moves");
        this.moves.addAll(moves);
    }

    /**
     * Returns the card for this play.
     *
     * @return the card for this play
     */
    public Card getCard() {
        return card;
    }

    /**
     * Returns the moves for this play.
     *
     * @return the moves for this play
     */
    public Set<Move> getMoves() {
        return moves;
    }

    @Override
    public int hashCode() {
        int hash = 7;        
        hash = 41 * hash + (this.card == null ? 0 : this.card.hashCode());
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Play other = (Play) obj;
        if (this.card == null && other.card != null) {
            return false;
        }
        if (!this.card.equals(other.card)) {
            return false;
        }
        if (this.moves == null && other.moves != null) {
            return false;
        }
        if (!this.moves.equals(other.moves)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {

        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.append(getClass().getName()).append("[");
        stringBuilder.append("card=").append(card == null ? null : card.toString());
        for (Move move : moves) {
            stringBuilder.append(",").append(move.toString());
        }
        stringBuilder.append("]");

        return stringBuilder.toString();

    }

}
